feat(sdk-coin-starknet): implement Starknet SDK module#8781
feat(sdk-coin-starknet): implement Starknet SDK module#8781shubham-damkondwar wants to merge 2 commits into
Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
b95cdbc to
ba966a5
Compare
| export const DECIMALS = 18; | ||
|
|
||
| // OZ EthAccountUpgradeable class hash (v0.17.0) — secp256k1 signature verification | ||
| export const OZ_ETH_ACCOUNT_CLASS_HASH = '0x3940bc18abf1df6bc540cabadb1cad9486c6803b95801e57b6153ae21abfe06'; | ||
|
|
||
| // STRK token contract (same on both mainnet and sepolia) | ||
| export const STRK_TOKEN_CONTRACT = '0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d'; | ||
|
|
||
| // ETH token contract on Starknet | ||
| export const ETH_TOKEN_CONTRACT = '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7'; | ||
|
|
||
| // Chain IDs | ||
| export const MAINNET_CHAIN_ID = '0x534e5f4d41494e'; // SN_MAIN | ||
| export const TESTNET_CHAIN_ID = '0x534e5f5345504f4c4941'; // SN_SEPOLIA | ||
|
|
||
| // RPC endpoints | ||
| export const MAINNET_RPC_URL = 'https://starknet-mainnet-rpc.publicnode.com/'; | ||
| export const TESTNET_RPC_URL = 'https://starknet-sepolia-rpc.publicnode.com/'; |
There was a problem hiding this comment.
these should be declared in modules/statics/src/networks.ts and used form there
| export interface StarknetTransactionData { | ||
| senderAddress: string; | ||
| calls: StarknetCall[]; | ||
| nonce?: string; |
There was a problem hiding this comment.
should nonce be optional ? as far as i remember nonce is serving the same purpose as evm nonce
| signature?: string[]; | ||
| transactionHash?: string; | ||
| // For token transfers | ||
| receiverAddress?: string; | ||
| amount?: string; | ||
| tokenContract?: string; |
There was a problem hiding this comment.
check for these optional fields as well
i feel like amount should not just be for token transfer and mandotory field
| id?: string; | ||
| sender: string; | ||
| senderPublicKey?: string; | ||
| recipient?: string; | ||
| amount?: string; | ||
| fee?: string; | ||
| nonce?: string; | ||
| type?: BitGoTransactionType; |
There was a problem hiding this comment.
same check for optional fields
| import { bip32 } from '@bitgo/secp256k1'; | ||
| import { randomBytes } from 'crypto'; | ||
|
|
||
| const DEFAULT_SEED_SIZE_BYTES = 16; |
There was a problem hiding this comment.
move to constants file
| if (!address || !utils.isValidAddress(address)) { | ||
| throw new BuildTransactionError('Invalid or missing address, got: ' + address); | ||
| } | ||
| if (pubKey && !utils.isValidPublicKey(pubKey)) { | ||
| throw new BuildTransactionError('Invalid pubKey, got: ' + pubKey); | ||
| } | ||
| this._sender = address; | ||
| if (pubKey) { | ||
| this._publicKey = pubKey; | ||
| } | ||
| return this; |
There was a problem hiding this comment.
we should have a check here that the address is corresponding to the public key
| public tokenContract(address: string): this { | ||
| if (!utils.isValidAddress(address)) { | ||
| throw new BuildTransactionError('Invalid token contract address'); | ||
| } | ||
| this._tokenContract = address; | ||
| return this; | ||
| } |
There was a problem hiding this comment.
i guess the tokenContract is something we have in our system. in the network.ts file
| validateTransaction(_transaction: Transaction): void { | ||
| // Subclasses provide specific validation | ||
| } |
There was a problem hiding this comment.
either implement the function or return not implemented error
| protected async buildImplementation(): Promise<Transaction> { | ||
| this.validateTransfer(); | ||
|
|
||
| const tokenContract = this._tokenContract || STRK_TOKEN_CONTRACT; |
There was a problem hiding this comment.
i think we should keep the _tokenContract fix and fetch from network.ts rather than letting the caller set it
| protected signImplementation(key: BaseKey): Transaction { | ||
| this.validateKey(key); | ||
| return this._transaction; | ||
| } |
There was a problem hiding this comment.
should function implement the signing logic
Summary
modules/sdk-coin-starknet— full unique chain SDK packageChain Type
ECDSA (secp256k1) — uses OZ EthAccountUpgradeable for account abstraction on Starknet L2
MPC Support
shouldHash=false(Poseidon pre-hashed transactions)[r_low, r_high, s_low, s_high, v]Reference Implementations
Changes
src/starknet.ts+tstarknet.ts— mainnet + testnet coin classessrc/lib/transactionBuilderFactory.ts— builder factorysrc/lib/transferBuilder.ts— STRK transfer transactions (ERC-20 calldata)src/lib/keyPair.ts— secp256k1 key pair with Starknet address derivationsrc/lib/transaction.ts— transaction parse/explain/serializesrc/lib/utils.ts— address validation, EthAccount address computation, signature formattingsrc/lib/iface.ts,constants.ts— types and chain constantstest/unit/— keyPair, transaction, builder, coin, and utils testsRelated
🤖 Generated with Claude Code